home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 80 / XENIATGM80.iso / Goodies / Blood 2 / Source / data.z / MessageMgr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-02  |  4.7 KB  |  219 lines

  1. //----------------------------------------------------------
  2. //
  3. // MODULE  : MessageMgr.h
  4. //
  5. // PURPOSE : Blood 2 Messaging system - Sorta derived from
  6. //             Blood's messaging system
  7. //
  8. // CREATED : 10/22/97
  9. //
  10. //----------------------------------------------------------
  11.  
  12. #ifndef __MESSAGEMGR_H__
  13. #define __MESSAGEMGR_H__
  14.  
  15.  
  16. #include "cpp_clientshell_de.h"
  17. #include "client_de.h"
  18. #include "DynArray.h"
  19. #include "SharedDefs.h"
  20.  
  21.  
  22. // defines
  23. #define MESSAGEFLAGS_INCOMING        0x01
  24. #define MESSAGEFLAGS_SELFGET        0x02
  25. #define MESSAGEFLAGS_OTHERGET        0x04
  26. #define MESSAGEFLAGS_RESPAWN        0x08
  27. #define MESSAGEFLAGS_MASK            0x0F
  28.  
  29.  
  30. #define MAXINPUTLINE    80
  31.  
  32. // Input line class
  33. class CInputLine
  34. {
  35.     public:
  36.  
  37.         CInputLine() 
  38.         { 
  39.             m_nTextLen = 0; 
  40.             *m_zText = '\0'; 
  41.             m_bShift = DFALSE;
  42.         }
  43.  
  44.         void        Init (CClientDE* pClientDE);
  45.         void        Clear( void );
  46.         void        Term( void );
  47.         void        Draw(HSURFACE hDest, HDEFONT hFont, HDECOLOR hForeColor, HDECOLOR hBackColor, long x, long y);
  48.         DBOOL        AddChar( DBYTE ch );
  49.         void        DelChar( void );
  50.         void        Set( char *pzText );
  51.         void        Send( void );
  52.         DBOOL        HandleKeyDown(int key, int rep);
  53.         void        HandleKeyUp(int key);
  54.  
  55.     private:
  56.  
  57.         char        AsciiXlate(int key);    // Translates VK_ values to ascii
  58.  
  59.         CClientDE*    m_pClientDE;            // the client interface
  60.         HSURFACE    m_hSurface;                // The surface to draw to
  61.         DBOOL        m_bShift;                // Shift is active
  62.         int            m_nTextLen;                // Current length of input string
  63.         char        m_zText[ MAXINPUTLINE + 2 ]; // The buffer
  64.  
  65. };
  66.  
  67. // Message structure
  68. struct Message
  69. {
  70.     Message()
  71.     {
  72.         hMessage = DNULL;
  73.         hSurface = DNULL;
  74.     }
  75.     DFLOAT fExpiration;
  76.     HSTRING  hMessage;
  77.     HSURFACE hSurface;
  78. };
  79.  
  80.  
  81. // Message manager class
  82. class CMessageMgr
  83. {
  84.     public:
  85.  
  86.         // Local constants
  87.         enum
  88.         {
  89.             kMaxMessages        = 20,
  90.             kMaxMessageSize        = 128,
  91.  
  92.             kDefaultMaxMessages    = 4,
  93.             kDefaultMessageTime    = 5,    // seconds
  94.         };
  95.  
  96.     public:
  97.  
  98.         CMessageMgr();
  99.     
  100.         DBOOL        Init (CClientDE* pClientDE);
  101.         void        Term ()  { Clear(); if (m_hFont) m_pClientDE->DeleteFont(m_hFont); }
  102.  
  103.         void        Enable( DBOOL bEnabled );
  104.  
  105.         void        AddLine( char *szMsg, DBYTE dbMessageFlag = MESSAGEFLAGS_MASK );
  106.         void        AddLine( HSTRING hMsg, DBYTE dbMessageFlag = MESSAGEFLAGS_MASK );
  107.         void        Clear( void );
  108.         void        Draw( void );
  109.         DBOOL        DrawCheatMsg( void );
  110.         DBOOL        HandleKeyDown(int key, int rep);
  111.         void        HandleKeyUp(int key) { m_InputLine.HandleKeyUp(key); }
  112.  
  113.         void        SetCoordinates( int x, int y );
  114.         void        SetMaxMessages( int nMaxMessages );
  115.         void        SetMessageTime( DFLOAT fSeconds );
  116.         void        SetMessageFlags( DDWORD dwFlags );
  117.         void        SetEditingState(DBOOL bEditing) { m_bEditing = bEditing; }
  118.  
  119.         DBOOL        GetState( void )        { return m_bEnabled; }
  120.         int            GetMaxMessages( void )    { return m_nMaxMessages; }
  121.         DFLOAT        GetMessageTime( void )    { return m_fMessageTime; }
  122.         DBOOL        GetEditingState() { return m_bEditing; }
  123.  
  124.     private:
  125.  
  126.         void        DeleteMessageData(Message *pMsg);
  127.  
  128.         CClientDE*    m_pClientDE;            // the client interface
  129.         CInputLine    m_InputLine;            // Current input message
  130.         HDEFONT        m_hFont;                // menu font
  131.  
  132.         DBOOL        m_bEnabled;
  133.         DBOOL        m_bEditing;
  134.  
  135.         int            m_x;
  136.         int            m_y;
  137.  
  138.         int            m_nFontHeight;
  139.  
  140.         int            m_nMaxMessages;
  141.         DFLOAT        m_fMessageTime;
  142.         DDWORD        m_dwMessageFlags;
  143.  
  144.         int            m_nMessageCount;
  145.         int            m_nFirstMessage;
  146.         int            m_nNextMessage;
  147.  
  148.         Message        m_Messages[ kMaxMessages ];
  149. };
  150.  
  151. inline void CMessageMgr::DeleteMessageData(Message *pMsg)
  152. {
  153.     if (pMsg)
  154.     {
  155.         if (pMsg->hSurface)
  156.         {
  157.             m_pClientDE->DeleteSurface(pMsg->hSurface);
  158.             pMsg->hSurface = DNULL;
  159.         }
  160.         if (pMsg->hMessage)
  161.         {
  162.             m_pClientDE->FreeString(pMsg->hMessage);
  163.             pMsg->hMessage = DNULL;
  164.         }
  165.     }
  166. }
  167.  
  168.  
  169. // Cheat Manager class
  170. class CCheatMgr
  171. {
  172.     friend        CMessageMgr;
  173.     public:
  174.         CCheatMgr() {}
  175.  
  176.         void    Init(CClientDE* pClientDE);
  177.  
  178.         void    Reset();
  179.  
  180.         DBOOL    Check( char *pzText );
  181.         void    ClearCheater() { m_bPlayerCheated = DFALSE; }
  182.         DBOOL    IsCheater() { return m_bPlayerCheated; }
  183.         DBOOL    IsCheatActive(CheatCodes nCheatCode) 
  184.         { 
  185.             if ( nCheatCode < CHEAT_NONE || nCheatCode >= CHEAT_MAX )
  186.                 return DFALSE;
  187.             else
  188.                 return s_CheatInfo[nCheatCode].bActive;
  189.         }
  190.  
  191.     protected:
  192.         void    Process( CheatCodes nCheatCode );
  193.  
  194.     private:
  195.  
  196.         void    SendCheatMessage( CheatCodes nCheatCode, DBOOL bState );
  197.         void    Decrypt();
  198.  
  199.         CClientDE*    m_pClientDE;            // the client interface
  200.  
  201.         struct CheatInfo
  202.         {
  203.             char            *pzText;
  204.             DBOOL            bActive;
  205.         };
  206.  
  207.         static CheatInfo s_CheatInfo[];
  208.  
  209.         static DBOOL m_bPlayerCheated;
  210.  
  211.         // Helper functions
  212.         void    ToggleCheat(CheatCodes eCheatCode, char* pOnMsg, char* pOffMsg);
  213.         void    ActivateCheat(CheatCodes eCheatCode, char* pOnMsg);
  214. };
  215.  
  216.  
  217.  
  218. #endif    // __MESSAGEMGR_H__
  219.